package com.hypo.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hypo.business.domain.User;
import com.hypo.business.domain.dto.LoginInfoDto;
import com.hypo.business.mapper.UserMapper;
import com.hypo.business.service.UserService;
import com.hypo.utils.JwtUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
@RequiredArgsConstructor
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    private final UserMapper userMapper;

    @Override
    public LoginInfoDto getToken(User userInfo) {
        //1.生成载荷
        HashMap<String, Object> claims = new HashMap<>();
        claims.put("userId", userInfo.getUserId());
        claims.put("nickName", userInfo.getNickName());
        claims.put("userName", userInfo.getUserName());
        //2.调用JwtUtils生成令牌
        String jwt = JwtUtils.generateJwt(claims);
        //3.返回LoginDto数据
        return new LoginInfoDto(userInfo.getUserId(), userInfo.getNickName(), userInfo.getUserName(), jwt,userInfo.getAvatar());
    }
}
